package pl.edu.pw.elka.dzielins.revanalyzer;

import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;

import edu.mit.csail.sdg.alloy4compiler.ast.Expr;
import edu.mit.csail.sdg.alloy4compiler.ast.Sig;

import pl.edu.pw.elka.dzielins.revanalyzer.alloy.io.Reader;
import pl.edu.pw.elka.dzielins.revanalyzer.instance.Instance;
import pl.edu.pw.elka.dzielins.revanalyzer.instance.InstanceObject;
import pl.edu.pw.elka.dzielins.revanalyzer.model.Model;
import pl.edu.pw.elka.dzielins.revanalyzer.model.ModelObject;

public class Project {
	private static final Logger LOG = Logger.getLogger(Project.class);
	
	private Model model;
	private Instance instance;
	
	public Project() {
		this.model = new Model();
		this.instance = new Instance();
	}
	
	// getters & setters

	public Model getModel() {
		return model;
	}

	public void setModel(Model model) {
		this.model = model;
	}

	public Instance getInstance() {
		return instance;
	}

	public void setInstance(Instance instance) {
		this.instance = instance;
	}
	
	// artificial getters & setters
	
	public List<Sig> getInstanceObjectsAsSigs() {
		List<Sig> sigs = new LinkedList<Sig>();
		return sigs;
	}
	
	public List<Expr> getInstanceAssignmentsAsExprs() {
		List<Expr> exprs = new LinkedList<Expr>();
		return exprs;
	}
	
	public List<InstanceObject> getInstanceObjectsFromModelObject(ModelObject modelObject) {
		return getInstanceObjectsFromModelObject(modelObject, false);
	}
	
	public List<InstanceObject> getInstanceObjectsFromModelObject(ModelObject modelObject, boolean inheritance) {
		if (instance == null)
			return null;
		List<InstanceObject> result = new LinkedList<InstanceObject>();
		for(InstanceObject io : instance.getObjects()) {
			if (io.getBaseObject() == modelObject || (inheritance && io.getBaseObject().inherits(modelObject)))
				result.add(io);
		}
		return result;
	}
}
